package xginxim

import (
	"encoding/json"

	"gitee.com/xiaoyutab/xgotool/optional/xim"
	"gitee.com/xiaoyutab/xgotool/xgin"
)

// 发送消息
//
//	POST	user.chat.send
func userChatSend(uid uint, b []byte) *xgin.Response {
	temp := xim.Message{}
	if err := json.Unmarshal(b, &temp); err != nil {
		return xgin.Resp().Error(err)
	}
	if temp.Id > 0 {
		return xgin.Resp().ErrorParam()
	}
	temp.UserId = uid
	if err := xim.CreateMessage(&temp); err != nil {
		return xgin.Resp().Error(err)
	}
	return xgin.Resp().SuccessEmpty()
}
